package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.entity.MemberAccount;
import com.xmall.auth.mapper.MemberAccountMapper;
import com.xmall.auth.service.IMemberAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 普通用户账户 服务实现类
 * </p>
 *
 * @author xmall
 * @since 2023-11-14
 */
@Slf4j
@Service
public class MemberAccountServiceImpl extends ServiceImpl<MemberAccountMapper, MemberAccount> implements IMemberAccountService {

    /**
     * 更新最后登录时间
     */
    @Override
    public Date updateLastLoginTime(Long userId, Integer accountType) {
        Date now = new Date();
        MemberAccount entity = this.getOne(new QueryWrapper<MemberAccount>().eq("user_id", userId).eq("type", accountType));
        if(null != entity){
            MemberAccount updateEntity = new MemberAccount();
            updateEntity.setId(entity.getId());
            updateEntity.setLastLoginTime(now);
            this.updateById(updateEntity);
        }
        if(null == entity) {
            log.error("updateLastLoginTime: 普通用户不存在 {}", userId);
        }
        return now;
    }
}
